﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace MvcControlsToolkit
{
    public abstract class Control: BaseObject
    {
        public HtmlHelper Helper { get; set; }
        public string Name { get; set; }

        public bool IsDisabled
        {
            get
            {
                if (Attributes.ContainsKey("disabled"))
                    return bool.Parse(Attributes["disabled"]);
                else return false;
            }
            set { Attributes["disabled"] = value.ToString().ToLower(); }
        }

        protected Control(string name)
        {
            if (String.IsNullOrEmpty(name))
                throw new Exception("Name cannot is null or empty");

            Name = name;
        }

        public virtual string Render()
        {
            var script = string.Format(ScriptManager.Script_template, GetJScript());

            var html = GetHtml();

            return html + script;
        }

        public override string ToString()
        {
            return Render();
        }

        public abstract string GetJScript();
        public abstract string GetHtml();
    }
}
